import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { useLoginUserStore } from '@/stores/loginUser'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      // children:[
      //   {
      //     path:'chat',
      //     name:'chat',
      //     component:() => import('@/views/homechileview/ChatView.vue')
      //   },
      //   {
      //     path:'friendList',
      //     name:'friendList',
      //     component:() => import('@/views/homechileview/FriendListView.vue')
      //   }
      // ]
    },
    {
      path:'/login',
      name:'login',
      component: () => import('@/views/LoginView.vue')
    }
  ]
})
router.beforeEach((to,from,next) => {
  const loginUserStore = useLoginUserStore()
  if(to.path === '/login'){
    next()
    return
  }
  if(loginUserStore.isLogin()) {
    next()
    return
  }else {
    router.push('/login')
  }
})
export default router
